<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>stringbuffer.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_string_stringbuffer.js.html">stringbuffer.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2006 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Utility for fast string concatenation.
<a name="line17"></a> */
<a name="line18"></a>
<a name="line19"></a>goog.provide(&#39;goog.string.StringBuffer&#39;);
<a name="line20"></a>
<a name="line21"></a>
<a name="line22"></a>
<a name="line23"></a>/**
<a name="line24"></a> * Utility class to facilitate string concatenation.
<a name="line25"></a> *
<a name="line26"></a> * @param {*=} opt_a1 Optional first initial item to append.
<a name="line27"></a> * @param {...*} var_args Other initial items to
<a name="line28"></a> *     append, e.g., new goog.string.StringBuffer(&#39;foo&#39;, &#39;bar&#39;).
<a name="line29"></a> * @constructor
<a name="line30"></a> */
<a name="line31"></a>goog.string.StringBuffer = function(opt_a1, var_args) {
<a name="line32"></a>  if (opt_a1 != null) {
<a name="line33"></a>    this.append.apply(this, arguments);
<a name="line34"></a>  }
<a name="line35"></a>};
<a name="line36"></a>
<a name="line37"></a>
<a name="line38"></a>/**
<a name="line39"></a> * Internal buffer for the string to be concatenated.
<a name="line40"></a> * @type {string}
<a name="line41"></a> * @private
<a name="line42"></a> */
<a name="line43"></a>goog.string.StringBuffer.prototype.buffer_ = &#39;&#39;;
<a name="line44"></a>
<a name="line45"></a>
<a name="line46"></a>/**
<a name="line47"></a> * Sets the contents of the string buffer object, replacing what&#39;s currently
<a name="line48"></a> * there.
<a name="line49"></a> *
<a name="line50"></a> * @param {*} s String to set.
<a name="line51"></a> */
<a name="line52"></a>goog.string.StringBuffer.prototype.set = function(s) {
<a name="line53"></a>  this.buffer_ = &#39;&#39; + s;
<a name="line54"></a>};
<a name="line55"></a>
<a name="line56"></a>
<a name="line57"></a>/**
<a name="line58"></a> * Appends one or more items to the buffer.
<a name="line59"></a> *
<a name="line60"></a> * Calling this with null, undefined, or empty arguments is an error.
<a name="line61"></a> *
<a name="line62"></a> * @param {*} a1 Required first string.
<a name="line63"></a> * @param {*=} opt_a2 Optional second string.
<a name="line64"></a> * @param {...*} var_args Other items to append,
<a name="line65"></a> *     e.g., sb.append(&#39;foo&#39;, &#39;bar&#39;, &#39;baz&#39;).
<a name="line66"></a> * @return {goog.string.StringBuffer} This same StringBuffer object.
<a name="line67"></a> * @suppress {duplicate}
<a name="line68"></a> */
<a name="line69"></a>goog.string.StringBuffer.prototype.append = function(a1, opt_a2, var_args) {
<a name="line70"></a>  // Use a1 directly to avoid arguments instantiation for single-arg case.
<a name="line71"></a>  this.buffer_ += a1;
<a name="line72"></a>  if (opt_a2 != null) { // second argument is undefined (null == undefined)
<a name="line73"></a>    for (var i = 1; i &lt; arguments.length; i++) {
<a name="line74"></a>      this.buffer_ += arguments[i];
<a name="line75"></a>    }
<a name="line76"></a>  }
<a name="line77"></a>  return this;
<a name="line78"></a>};
<a name="line79"></a>
<a name="line80"></a>
<a name="line81"></a>/**
<a name="line82"></a> * Clears the internal buffer.
<a name="line83"></a> */
<a name="line84"></a>goog.string.StringBuffer.prototype.clear = function() {
<a name="line85"></a>  this.buffer_ = &#39;&#39;;
<a name="line86"></a>};
<a name="line87"></a>
<a name="line88"></a>
<a name="line89"></a>/**
<a name="line90"></a> * @return {number} the length of the current contents of the buffer.
<a name="line91"></a> */
<a name="line92"></a>goog.string.StringBuffer.prototype.getLength = function() {
<a name="line93"></a>  return this.buffer_.length;
<a name="line94"></a>};
<a name="line95"></a>
<a name="line96"></a>
<a name="line97"></a>/**
<a name="line98"></a> * @return {string} The concatenated string.
<a name="line99"></a> * @override
<a name="line100"></a> */
<a name="line101"></a>goog.string.StringBuffer.prototype.toString = function() {
<a name="line102"></a>  return this.buffer_;
<a name="line103"></a>};
</pre>


</body>
</html>
